<template>
  <div class="htmlbox">
    <div class="vippage">
      <div class="title">
        <van-nav-bar
          left-arrow
          :border="false"
          @click-left="onClickLeft"
          title="樊登讲述VIP"
        />
      </div>
      <div class="vipcar">
        <div class="left">
          <div class="userface" @click="gotoDetails">
            <img :src="userimg" alt="" @click="gotoDetails" v-if="userimg" />
          </div>
          <!-- 如果登录 -->
          <div v-if="token" class="username">
            <b>{{ username }}</b>
            <!-- 会员未到期 -->
            <span v-if="downtime"
              >樊登会员：{{ totime }}到期<van-icon name="edit"
            /></span>
            <!-- 会员已过期 -->
            <span v-else>会员已过期</span>
          </div>
          <!-- 未登录 -->
          <b v-else class="username">
            <p>
              <b @click="gotologin">登录 </b> /
              <b @click="gotoregistry"> 注册</b>
            </p>
            <span>体验已过期</span>
          </b>
        </div>
        <div class="right">
          <span v-if="downtime" @click="openvip">会员续费</span>
          <span v-else @click="openvip">立即开通</span>
        </div>
        <div class="vippice"><i>￥</i><span>365</span><b>每天仅需1元钱</b></div>
      </div>
      <div class="tenquanyi">
        <div class="titlemin">尊享10权益</div>
        <div class="fourquanyi">
          <div class="biaoti">
            <i></i><span>基础权益 |</span><b>樊登讲书VIP 4大权益</b>
          </div>
          <div class="list list1">
            <div v-for="(item, index) in list4" :key="index" class="mains">
              <img :src="item.url" alt="" />
              <span>{{ item.btitle }}</span>
              <b>{{ item.mtitle }}</b>
            </div>
          </div>
        </div>
        <div class="line"></div>
        <div class="sixquanyi">
          <div>
            <div class="biaoti">
              <i></i><span>升级权益 |</span><b>更多内容产品 6项体验特权</b>
            </div>
            <!-- 横向滚动 -->
            <div class="parenbox">
              <div class="list">
                <div
                  v-for="(item, index) in list6"
                  :key="index"
                  class="mains mains2"
                >
                  <img :src="item.url" alt="" />
                  <span>{{ item.btitle }}</span>
                  <b>{{ item.mtitle }}</b>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="nowvipsend">
        <div class="titlemin">现在开通VIP 免费得</div>
        <div class="radener">
          <p class="smallfont">
            VIP开通成功后，可在【我的】-【已购】中查看到账福利
          </p>
          <div
            v-for="(item, index) in openvipdata"
            :key="index"
            class="experience"
          >
            <p class="title"><i></i> {{ item.title }}</p>
            <div
              v-for="(val, index) in item.mains"
              :key="index"
              class="bookcar"
            >
              <img :src="val.src" alt="" />
              <div class="rightbox">
                <h4>{{ val.booknm }}</h4>
                <p>{{ val.detailtext }}</p>
                <p>{{ val.writer }}</p>
                <p>
                  <span>价值 ￥{{ val.price }}</span
                  ><b>免费得</b>
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
      <van-action-bar safe-area-inset-bottom placeholder>
        <div class="footopenvip" @click="openvip">
          <p>开通樊登讲书VIP</p>
          <span>¥365/年</span>
        </div>
      </van-action-bar>
    </div>
  </div>
</template>

<script>
import { ref, onMounted, onBeforeMount } from "vue";
import { useRouter } from "vue-router";
import { postEditChaXunApi } from "../utils/loginapi";
import { Dialog } from "vant";
import BetterScroll from "better-scroll";
export default {
  setup() {
    // 获取本地token判断是否登录
    const token = localStorage.getItem("token");
    // 用户名
    const username = ref("");
    const userimg = ref("");
    onBeforeMount(() => {
      if (token) {
        postEditChaXunApi({ usertel: token }).then((res) => {
          username.value = res.data.username;
          userimg.value = res.data.userimg;
        });
      }
    });

    //会员是否过期
    const downtime = false;
    // 会员到期时间
    const totime = "2021年8月31日";

    const list4 = [
      {
        btitle: "300+书",
        mtitle: "畅听下载",
        url: "https://i.loli.net/2021/07/18/eQgSlHbItqXmuNn.png",
      },
      {
        btitle: "思维导图",
        mtitle: "免费学习",
        url: "https://i.loli.net/2021/07/18/rzIkC2sPyFb1OmL.png",
      },
      {
        btitle: "VIP礼品卡",
        mtitle: "亲友同享",
        url: "https://i.loli.net/2021/07/18/pEcAMBH69RnCVqk.png",
      },
      {
        btitle: "主题书单",
        mtitle: "轻松选书",
        url: "https://i.loli.net/2021/07/18/7NwaS62eGX4FKU3.png",
      },
    ];
    const list6 = [
      {
        btitle: "大咖课程",
        mtitle: "专享体验",
        url: "https://i.loli.net/2021/07/18/MdHEAeB2hFDuQpq.png",
      },
      {
        btitle: "新知父母",
        mtitle: "能力解锁",
        url: "https://i.loli.net/2021/07/18/ao5gRJkB2EN1Z9h.png",
      },
      {
        btitle: "非凡精读",
        mtitle: "抢先学习",
        url: "https://i.loli.net/2021/07/18/eDNYC2qQVWMnSrZ.png",
      },
      {
        btitle: "专业课程",
        mtitle: "尽享优惠",
        url: "https://i.loli.net/2021/07/18/zW5e73AvIJZjaHt.png",
      },
      {
        btitle: "樊登讲书",
        mtitle: "轻松学习",
        url: "https://i.loli.net/2021/07/18/MdHEAeB2hFDuQpq.png",
      },
    ];
    const openvipdata = [
      {
        title: "大咖课程 专享体验",
        mains: [
          {
            booknm: "活出漂亮人生-女性成长十节课",
            writer: "苏芒",
            detailtext: "苏芒：女人不苦不累的聪明活法",
            price: 19.9,
            src: "https://i.loli.net/2021/07/18/ONC5n143c9umbyk.png",
          },
          {
            booknm: "曾仕强易经的智慧 精选福袋",
            writer: "曾仕强",
            detailtext: "越早读懂易经越好命",
            price: 39,
            src: "https://i.loli.net/2021/07/18/3bXTJjmwr1g2VRa.png",
          },
          {
            booknm: "《复旦名师中国通史课》精选福袋",
            detailtext: "50本书读懂中国历史",
            writer: "姜鹏",
            price: 9.9,
            src: "https://i.loli.net/2021/07/18/SnjCLiMu5H24qOd.png",
          },
          {
            booknm: "新父母5门必修大课10讲",
            detailtext: "WWEC教育者大会获奖亲子课",
            writer: "樊登新父母导师团",
            price: 68,
            src: "https://i.loli.net/2021/07/18/CtYm54lFs3WIJQ7.png",
          },
        ],
      },

      {
        title: "非凡精读 抢先学习",
        mains: [
          {
            booknm: "《给青少年的中国文化课》 畅听版",
            writer: "余秋雨·著名文化学者",
            detailtext: "余秋雨送给年轻人的中国文化必",
            price: 19.9,
            src: "https://i.loli.net/2021/07/18/qSjVvibYLrCNFZI.png",
          },
          {
            booknm: "《人生的智慧》畅听版",
            writer: "徐英瑾·复旦大学教授",
            detailtext: "在无常的命运中，找到幸福人生",
            price: 9.8,
            src: "https://i.loli.net/2021/07/18/jqyQdha1UkvAPL3.png",
          },
        ],
      },
    ];
    // 事件
    const openvip = () => {
      Dialog({ message: "暂不支持该浏览器" });
    };
    // 路由跳转
    const $router = useRouter();
    const onClickLeft = () => {
      $router.go(-1);
    };
    // 跳转注册页
    const gotoregistry = () => {
      $router.push("/registry");
    };
    // 跳转登录页
    const gotologin = () => {
      $router.push("/login");
    };
    // 跳转到个人详情页
    const gotoDetails = () => {
      if (token) {
        $router.push("/details");
      }
    };
    onMounted(() => {
      new BetterScroll(".parenbox", {
        scrollX: true,
        scrollY: false,
        click: true,
      });
    });
    return {
      token,
      onMounted,
      username,
      userimg,
      downtime,
      totime,
      list4,
      list6,
      openvipdata,
      openvip,
      onClickLeft,
      gotoregistry,
      gotologin,
      gotoDetails,
    };
  },
};
</script>

<style lang="less">
:root {
  --van-nav-bar-icon-color: #fff;
  --van-nav-bar-arrow-size: 15px;
}
.vippage {
  font-family: PingFang SC;
  color: #c1650f;
  position: relative;
  overflow: hidden;
  width: 100%;

  // 顶部背景
  &::after {
    content: "";
    display: block;
    position: absolute;
    width: 800px;
    height: 800px;
    border-radius: 100%;
    background: linear-gradient(90deg, #1a1a1a 0%, #868686 100%);
    left: 50%;
    top: -600px;
    transform: translateX(-50%);
    z-index: -1;
  }
  // 顶部标题
  .van-nav-bar {
    background: transparent;
    .van-nav-bar__title {
      color: #fff;
      font-size: 17px;
      color: #ffffff;
      line-height: 23px;
    }
  }
  // 等宽圆角
  .vipcar,
  .tenquanyi,
  .footopenvip,
  .nowvipsend {
    width: 336px;
    border-radius: 10px;
    margin: 15px auto;
    box-shadow: 0px 0px 8px 0px rgba(129, 72, 21, 0.25);
  }
  .line {
    width: 80%;
    height: 1px;
    background: #e2e1e0;
    margin: auto;
  }
  .vipcar {
    height: 150px;
    padding: 15px 20px;
    box-sizing: border-box;
    position: relative;
    background: linear-gradient(-90deg, #fbe6c9 0%, #f7d5a4 100%);
    .left {
      display: flex;
      align-items: center;
      .userface {
        display: inline-block;
        width: 62px;
        height: 62px;
        border-radius: 100%;
        background: #ccc;
        overflow: hidden;
        border: 4px solid #fde351;
        box-sizing: border-box;
        box-shadow: 0 0 4px rgba(0, 0, 0, 0.151);
        img {
          width: 62px;
          height: 62px;
        }
      }
      .username {
        display: flex;
        flex-direction: column;
        justify-content: center;
        margin-left: 7px;
        b {
          font-size: 18px;
          font-weight: bold;
          color: #a36021;
          line-height: 18px;
        }
        span {
          margin-top: 5px;
          font-size: 12px;
          color: #a36021;
          line-height: 18px;
        }
      }
    }
    .right {
      position: absolute;
      right: 20px;
      bottom: 20px;
      span {
        width: 96px;
        height: 32px;
        background: #d3751f;
        box-shadow: 0px 3px 4px 0px rgba(129, 72, 21, 0.55);
        border-radius: 18px;
        line-height: 32px;
        text-align: center;
        display: block;
        font-size: 16px;
        color: #fefefe;
      }
    }
    .vippice {
      position: absolute;
      left: 20px;
      bottom: 25px;
      i {
        font-size: 15px;
        color: #c1650f;
        line-height: 23px;
        font-style: normal;
      }
      span {
        font-size: 27px;
        color: #c1650f;
        line-height: 26px;
      }
      b {
        font-size: 10px;
        color: #a76628;
        line-height: 23px;
      }
    }
  }
  .titlemin {
    height: 40px;
    background: linear-gradient(0deg, #ffe2b9 0%, #ffeacc 100%);
    border-radius: 9px 9px 0px 0px;
    font-size: 16px;
    font-weight: bold;
    color: #a76628;
    line-height: 40px;
    text-align: center;
  }
  .fourquanyi,
  .sixquanyi {
    font-size: 15px;
  }
  // 横向滚动
  .parenbox {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }
  .list1 {
    width: 100%;
  }
  .list {
    padding: 0 30px;
    display: inline-flex;
    padding-bottom: 20px;
    .mains2 {
      width: 30%;
      margin: 0 10px;
      height: auto;
    }
    .mains {
      width: 25%;
      display: flex;
      flex-direction: column;
      align-items: center;
      span {
        font-size: 12px;
        font-weight: bold;
        color: #4d4a4a;
        line-height: 23px;
      }
      b {
        font-size: 10px;
        font-weight: normal;
        color: #b6b6b6;
        line-height: 10px;
      }
      img {
        width: 49px;
        height: 49px;
      }
    }
  }
  .biaoti {
    height: 50px;
    line-height: 50px;
    margin: 0 15px;
    span {
      font-size: 16px;
      color: #73554c;
      line-height: 23px;
    }
    b {
      font-size: 14px;
      color: #94807a;
      line-height: 23px;
    }
    i {
      display: inline-block;
      width: 8px;
      height: 8px;
      background: #77594f;
      border-radius: 50%;
      margin: 0 10px;
    }
  }
  .radener {
    .smallfont {
      text-align: center;
      font-size: 10px;
      color: #939393;
      line-height: 23px;
    }
    &:nth-child(2) {
      margin-bottom: 80px;
    }
    .experience {
      padding-bottom: 30px;
      .title {
        font-size: 15px;
        font-weight: bold;
        color: #a8672a;
        line-height: 23px;
        padding: 0 15px;
        vertical-align: middle;

        i {
          vertical-align: middle;
          line-height: 23px;
          display: inline-block;
          width: 3px;
          height: 15px;
          background: #a8672a;
          border-radius: 3px;
        }
      }
      .bookcar {
        display: flex;
        padding: 15px;
        img {
          width: 85px;
        }
        .rightbox {
          width: 100%;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          margin-left: 15px;
          h4 {
            font-size: 16px;
            color: #565352;
          }
          p {
            font-size: 13px;
            color: #949494;
            display: flex;
            justify-content: space-between;
            b {
              font-weight: normal;
            }
          }
          span {
            font-size: 14px;
            font-weight: bold;
            color: #fa6200;
          }
        }
      }
    }
  }
  .footopenvip {
    background: #d27621;
    height: 45px;
    border-radius: 23px;
    text-align: center;
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    p {
      font-size: 18px;
    }
    span {
      font-size: 11px;
    }
  }
}
</style>
